package games.ninJumpDx.data
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	public class GameData extends EventDispatcher
	{
		public static const SPEED_CHANGE:String = "speed change"; // 速度改变 
		public static const KILL_ENEMY:String   = "kill enemy";	  // 杀死敌人
		public static const SCORE_CHANGE:String  = "score change";  // 杀死敌人类型改变
		public static const MUSIC_CHANGE:String = "music change";	// 音乐开关状态改变
		public static const SOUND_CHANGE:String = "sound change";	// 生效开关状态改变
		private static var m_instance:GameData;
		private var m_speed:Number;
		private var m_kills:Number;
		private var m_type: String;
		private var m_score:Number;
		private var m_music:Boolean;
		private var m_sound:Boolean;
		
		public function GameData(s:single)
		{
			init();
		}
		
		public static function get instance():GameData
		{
			if(!m_instance)
			{
				m_instance = new GameData(new single());
			}
			return m_instance;
		}
		
		private function init():void
		{
			m_score = 0;
			m_speed = 5;
			m_kills = 0;
			m_type = "";
			m_music = false;
			m_sound = false;
		}
		
		public function set score(n:Number):void
		{
			m_score = n;
			dispatchEvent(new Event(SCORE_CHANGE));
		}
		
		public function get score():Number
		{
			return m_score;
		}
		
		public function set speed(n:Number):void
		{
			m_speed = n;
			dispatchEvent(new Event(SPEED_CHANGE));
		}
		
		public function get speed():Number
		{
			return m_speed;
		}
		
		public function set kills(n:Number):void
		{
			m_kills = n;
			dispatchEvent(new Event(KILL_ENEMY));
		}
		
		public function get kills():Number
		{
			return m_kills;
		}
		
		public function set type(s:String):void
		{
			if(m_type == s)
			{
				kills ++;
				return;
			}
			
			m_type = s;
			kills = 1;
		}
		
		public function get type():String
		{
			return m_type;
		}
		
		public function set music(b:Boolean):void
		{
			m_music = b;
			dispatchEvent(new Event(MUSIC_CHANGE));	
		}
		
		public function get music():Boolean
		{
			return m_music;
		}
		
		public function set sound(b:Boolean):void
		{
			m_sound = b;
			dispatchEvent(new Event(SOUND_CHANGE));	
		}
		
		public function get sound():Boolean
		{
			return m_sound;
		}
	}
}
class single{}